package com.example.smartcity.ui.act

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.smartcity.R
import com.example.smartcity.adapter.SearchResultAdapter
import com.example.smartcity.app.App
import com.example.smartcity.http.SellerListResp
import kotlinx.android.synthetic.main.activity_tof_search_result.*
import kotlinx.android.synthetic.main.layout_app_bar_common.*

class TOFSearchResultActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_tof_search_result)
        tvAppBarTitle.text = "搜索结果"
        ivAppBarLeft.setOnClickListener { finish() }
        renderSellerData(intent.extras?.get("search_result") as String)
    }

    // 渲染搜索结果
    private fun renderSellerData(data: String) {
        var sellerListResp: SellerListResp = App.json2Object(data, SellerListResp::class.java)!!
        val linearLayoutManager = LinearLayoutManager(this@TOFSearchResultActivity)
        linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
        rvSearchResult.layoutManager = linearLayoutManager
        rvSearchResult.adapter = SearchResultAdapter(
            sellerListResp.rows,
            object : SearchResultAdapter.OnItemClickListener {
                override fun onClick(position: Int) {
                }
            }, this
        )
    }
}